function plot_compare_MM1_MMm_mMM1(lambda, starting_mu, ending_mu, step_mu, m, testno)
%**************************************************************************
% Author: Eric Humenay, ebh5n@cs.virginia.edu; Xiuduan Fang, xf4c@virginia.edu; 
% Date: Nov 20, 2006
%
% This function plots utilization, mean number of customers in the system and mean response time per customer 
% against mu in three types of systems: MM1, MMm, and m MM1.
% lamda: call arrival rate
% starting_mu: lower bound for mu 
% starting_mu: upper bound for mu
% step_mu: set step_mu a smaller value if you want finer granularity
% m: number of customer
%***********************************************************************************************************************  
if lambda<=0
    fprintf ('Syntax: plot_compare_MM1_MMm_mMM1(lambda, starting_mu, ending_mu, step_mu, m, testno)');
    error ('Bad parameter: lambda shoud be greater than 0 ');
elseif starting_mu<=0
    fprintf ('Syntax: plot_compare_MM1_MMm_mMM1(lambda, starting_mu, ending_mu, step_mu, m, testno)');
    error ('Bad parameter: starting_mu shoud be greater than 0 ');
elseif ending_mu<starting_mu
    fprintf ('Syntax: plot_compare_MM1_MMm_mMM1(lambda, starting_mu, ending_mu, step_mu, m, testno)');
    error ('Bad parameter: lambda_upper should be greater than lambda_lower ');
elseif step_mu<0
    fprintf ('Syntax: plot_compare_MM1_MMm_mMM1(lambda, starting_mu, ending_mu, step_mu, m, testno)');
    error ('Bad parameter: step_mu should be greater than 0 ');
elseif (m~=ceil(m)) || (m<=0)
    fprintf ('Syntax: plot_compare_MM1_MMm_mMM1(lambda, starting_mu, ending_mu, step_mu, m, testno)');
    error ('Bad parameter: m should be a positive integer');
end

mu = [starting_mu:step_mu:ending_mu]; 
index = floor(((ending_mu-starting_mu)/step_mu)) + 1;

%function [U, EN, ET, EW, ENQ] = MM1(lambda, mu)
%function [Pq, U, EN, ET, EW, EWd, ENQ]=MMm(lambda,mu,m)
%function [U, EN, ET, EW] = mMM1(lambda, mu, m)

for i= 1:index
    [U_MM1(i), EN_MM1(i), ET_MM1(i), EW_MM1_temp, ENQ_MM1_temp] = MM1(lambda, mu(i));
    [Pq_MMm_temp, U_MMm(i), EN_MMm(i), ET_MMm(i), EW_MMm_temp, EWd_MMm_temp, ENQ_MMm_temp]=MMm(lambda,mu(i),m);
    [U_mMMm(i), EN_mMMm(i), ET_mMMm(i), EW_mMMm_temp] = mMM1(lambda, mu(i), m);
end

%---------------------------------------------------------------------------------------------------------------
testfilename =  strcat('plot_compare_MM1_MMm_mMM1', num2str(testno));
testfilename = strcat(testfilename, '.txt');
fprintf('Output file %s is created in the current directory, which is set to be:\n', testfilename);
pwd
outfile=fopen(testfilename,'w+');  
fprintf(outfile,'lambda = %f \n',lambda);
fprintf(outfile,'starting_mu = %f \n',starting_mu);
fprintf(outfile,'ending_mu = %f \n',ending_mu);
fprintf(outfile,'step_mu = %f \n',step_mu);
fprintf(outfile,'m= %d\n',m);

fprintf(outfile, '                    MM1                        MMm                               mMMm \n');
fprintf(outfile, 'U_MM1     EN_MM1      ET_MM1      U_MMm      EN_MMm      ET_MMm       U_mMMm     EN_mMMm      ET_mMMm\n');
fprintf(outfile, '=======================================================================================================\n');

for i= 1:index
     fprintf(outfile, '%.6f   %.6f   %.6f   %.6f   %.6f   %.6f   %.6f   %.6f   %.6f\n',U_MM1(i), EN_MM1(i), ET_MM1(i), ...
         U_MMm(i), EN_MMm(i), ET_MMm(i),U_mMMm(i), EN_mMMm(i), ET_mMMm(i));
end
fclose(outfile);

h=figure;
subplot(1,3,1);
hold on
plot(mu,waitingtime);
annotation_index = round(1/3 * index);
annotation_x = mu(annotation_index);
annotation_y = waitingtime(annotation_index);
text(annotation_x,annotation_y,['\lambda=',num2str(lambda),', server=',num2str(server),', customer=',num2str(customer)],'Fontname', 'times', 'HorizontalAlignment','left','FontSize',10); 
xlabel(' \mu','FontSize',10);
ylabel('waitingtime','FontSize',10');
hold off
figurefilename = strcat('plot_compare_MM1_MMm_mMM1',num2str(testno));
figfilename = strcat(figurefilename, '.fig');
saveas(h,figfilename);

